{extend name="common/public" /}
{block name="content"}

<div class="widget-body am-fr">
    <div class="am-form-group">
        <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
                <button type="button" onclick="openUrl('{:url("adduser")}','添加')" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
            </div>
        </div>
    </div>
</div>

<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
    <div class="widget am-cf">
        <div class="widget-head am-cf">
            <div class="widget-title am-fl">
                {if $Request.param.parent_id}
                    {if $parent_info.true_name}
                        {$parent_info.true_name}
                    {else /}
                        {$parent_info.nickname}
                    {/if}
                    : {$parent_info.telephone} 的推广人员
                {else /}
                    用户列表
                {/if}
            </div>
            <div class="widget-function am-fr">
                <a href="javascript:;" class="am-icon-cog"></a>
            </div>
        </div>
        <div>
            <form action="{:url()}">
                <span id="yunyin">
                    <select name="operate_id" data-type="type_1" type="1" onchange="getNext(this)" required="required">
                        <option value="0">所有运营中心</option>
                        {foreach $operate as $v}
                            <option  value="{$v.id}" {if $v.id == input('param.operate_id',0)}selected{/if}> {$v.name}</option>
                        {/foreach}

                    </select>
                    {if $Request.param.parent_id}
                        <input type="hidden" name="parent_id" value="{$Request.param.parent_id}">
                    {/if}
                </span>
                    <select name="agent_id">
                        <option value="">全部岗位</option>
                        {foreach $agent as $v}
                            <option value="{$v.id}" {if $v.id ==  input('param.agent_id',0)}selected{/if}>{$v.name}</option>
                        {/foreach}
                    </select>
                    <select name="type">
                        <option value="">全部类型</option>
                        <option value="1" {if 1==  $Request.param.type}selected{/if}>用户</option>
                        <option value="2" {if 2==  $Request.param.type}selected{/if}>企业</option>
                    </select>
                <input type="text" style="width: 300px" value="{$Request.get.searchKeyWords}" name="searchKeyWords" placeholder="搜索用户昵称|电话号码|推荐码"/>
                    <button type="submit" class="am-btn am-btn-xs am-btn-default am-btn-success"><span class="am-icon-search"></span> 确定</button>
            </form>
        </div>

        <div class="widget-body  widget-body-lg am-fr">


            <table width="100%" class="am-table am-table-compact am-table-bordered tpl-table-black ">
                <thead>

                <tr>
                    <th>昵称</th>
                    <th>手机号码</th>
                    <th>余额</th>
                    <th>真实姓名</th>
                    <th>用户级别</th>
                    <th>合伙人级别</th>
                    <th>岗位级别</th>
                    <th>直推人数</th>
                    <th>团队人数</th>
                    <th>上级推荐人</th>
                    <th>状态</th>
                    <th>注册时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                {foreach $list as $v}

                <tr class="gradeX">
                    <td> {$v.nickname}</td>
                    <td> {$v.telephone}</td>
                    <td>￥ <span style="color:red;font-size: 14px">{:number_format($v.commission/100,2)}</span></td>
                    <td> {$v.true_name}</td>
                    <td style="color: red"> {eq name='$v.type' value='1'}合伙人{else/}企业{/eq}</td>
                    <td>
                        <span style="color:green;">
                            {$v.agent_name}
                        </span>
                    </td>
                    <td>
                        <span style="color:green;">
                            {$v.user_job_name}
                        </span>
                    </td>
                    <td> {$v.recommend_number}</td>
                    <td> {$v.agent_count}</td>
                    <td> {$v.parent_telephone}</td>
                    <td>
                        <div class="tpl-switch">
                            <input type="checkbox" id="lock" onchange="changeStatus(this,{$v.id})"  class="ios-switch bigswitch tpl-switch-btn am-margin-top-xs" {present name='$v.lock'}{eq name='$v.lock' value="1"}checked{/eq} {else}checked{/present}>
                            <div class="tpl-switch-btn-view">
                                <div></div>
                            </div>
                        </div>
                    </td>
                    <td>{$v.create_time}</td>
                    <td>
                        <div class="tpl-table-black-operation">
                            <a onclick="openUrl('{:url('userinfo',['id'=>$v['id']])}','个人详情')">
                                <i class="am-icon-eye"></i> 个人信息
                            </a>
                            {if $v.recommend_number}
                                <a href="{:url('',['parent_id'=>$v['id']])}">
                                    <i class="am-icon-eye"></i> 直推
                                </a>
                            {/if}
                            {if $v.agent_grade>2}
                                <a onclick="openUrl('{:url('editUser',['id'=>$v['id']])}')">
                                    <i class="am-icon-edit"></i> 升级
                                </a>
                            {/if}
                            {if $v.type == 2}
                                <a onclick="openUrl('{:url('editUser',['id'=>$v['id']])}')">
                                    <i class="am-icon-edit"></i> 企业分成规则
                                </a>
                            {/if}
                        </div>
                    </td>
                </tr>
                {/foreach}
                </tbody>
                </table>
            {$list|raw}
        </div>
    </div>
</div>

{/block}
{block name='script'}
<script type="text/javascript">
    function changeStatus(dom,user_id){

        var lock = 1;
        if(!dom.checked){
            lock = 0;
        }

        $.post('lock',{user_id:user_id,lock:lock})
    }
    function getNext(dom) {
        var id = parseInt($(dom).attr('type'));
        var nextDom = $('select[data-type="type_'+(id+1)+'"]');
        if(dom.value ==0){
            nextDom.next('br').remove();
            nextDom.remove();
        }


        $.get("{:url('operate/getNextOperate')}",{id:dom.value},function (result) {

            var htm= '<option value="'+dom.value+'">全部</option>';
            if(result.length ==0){
                nextDom.next('br').remove();
                nextDom.remove();
                return;
            }
            for(var i=0;i<result.length;i++){
                htm+='<option value="'+result[i].id+'">'+result[i].name+'</option>'
            }
            if(nextDom.get(0) ==undefined){
                htm = "<select style='margin-left: 10px;' name='operate_id' data-type='type_"+(id+1)+"' type='"+(id+1)+"'  onchange=\"getNext(this)\">"+htm+"</select>"
                $('#yunyin').append(htm)
            }else{
                nextDom.html(htm)
            }
        },'json')
    }
</script>
{/block}
{/extend}